package filters

import (
	"gitchina/kly_service/models"
	"gitchina/kly_service/util"
	_ "github.com/astaxie/beego"
	"github.com/astaxie/beego/context"
	"net/http"
)

var exclude_map = map[string]byte{
	"101000": 1,
	"102001": 1,
	"102030": 1,
	"102031": 1,
	"102032": 1,
	"108003": 1,
	"108004": 1,
	"109001": 1,
	"109002": 1,
	"109003": 1,
	"109004": 1,
	"109005": 1,
	"109006": 1,
}

var VersionFilterFunc = func(ctx *context.Context) {
	id, ok := ctx.Input.Params()[":id"]
	if ok {
		if _, ok := exclude_map[id]; !ok {
			var general models.General
			ver := ctx.Request.Header.Get("version")
			if err := general.CheckVersion(ver); err != nil {
				util.GetLogger().Error("[filter-version] - ver:%s. error:%s", ver, err.Error())
				http.Error(ctx.ResponseWriter, "", 426)
			}
		}
	}
}
